package com.right.health.app.ui.me;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.magic.basic.activity.BaseActivity;
import com.magic.basic.utils.ToastUtil;
import com.magics.http.listener.OnHttpListener;
import com.magics.http.model.Request;
import com.magics.http.model.Response;
import com.right.health.app.R;
import com.right.health.app.app.App;
import com.right.health.app.constants.BroadCastCode;
import com.right.health.app.net.UserApi;

/*
 * Created by hopeliao on 2019-09-29
 * 就诊卡添加
 *
 */
public class MeVisitCardAddActivity extends BaseActivity implements View.OnClickListener, OnHttpListener {

    private static final String EXTRA_KEY = "memberId";

    private EditText mContentEt;

    private UserApi mUserApi;

    private String mMemberid;

    @Override
    public void onCreate(Bundle bundle, String s) {
        setContentView(R.layout.me_visit_card_add);
    }

    @Override
    public void findView() {
        findViewById(R.id.tv_choose_hospital).setOnClickListener(this);
        findViewById(R.id.tv_add).setOnClickListener(this);
        findViewById(R.id.tv_add_auto).setOnClickListener(this);

        mContentEt = (EditText) findViewById(R.id.tv_content);
    }

    @Override
    public void initialize() {
        mUserApi = new UserApi();
        mUserApi.setListener(this);

        mMemberid = App.getInstance().getCurrentMember().id;
        Bundle bundle = getIntent().getExtras();
        if(bundle != null && bundle.containsKey(EXTRA_KEY)) {
            mMemberid = bundle.getString(EXTRA_KEY);
        }
    }

    public static void applyActivity(Activity act, String memberid) {
        Intent intent = new Intent(act, MeVisitCardAddActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString(EXTRA_KEY, memberid);
        intent.putExtras(bundle);

        act.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_choose_hospital: //选择医院
                break;
            case R.id.tv_add: //手动添加
                send2Net();
                break;
            case R.id.tv_add_auto: //自动添加

                break;
        }
    }

    private void send2Net() {
//        String content = mContentEt.getText().toString().trim();
//        if(TextUtils.isEmpty(content)) {
//            ToastUtil.show(this, "请输入就诊卡/住院号");
//            return;
//        }
        if(TextUtils.isEmpty(mMemberid)) {
            return;
        }
        mUserApi.addVisitCard(getResources().getString(R.string.def_hospital_code), mMemberid);
    }


    @Override
    public void onResponse(Request request, Response response) {
        if(response.isResponseFail()) {
            ToastUtil.show(this, response.error);
        } else {
            ToastUtil.show(this, "保存成功");
            sendBroadcast(BroadCastCode.REFRESH_VISITCARD);
            finish();
        }
    }
}
